package ua.pp.bizon.yandex.uploader.atom;

import ua.pp.bizon.yandex.uploader.remote.RemotePhotoCreator;

import org.apache.abdera.model.Element;
import org.apache.http.HttpException;

public class Photo extends Entry implements Comparable<Photo> {

	public Photo(Element e) {
		super(e);
	}

	public String getName() {
		return getFirst("title").getText();
	}

	public void setName(String name) throws HttpException {
		String oldName = getName();
		try {
			getFirst("title").setText(name);
			updateElement(new RemotePhotoCreator().update(this).getElement());
		} catch (HttpException e) {
			getFirst("title").setText(oldName);
			throw e;
		}
	}

	@Override
	public String toString() {
		return "Photo:[" + getElement() + "]";
	}

	@Override
	public int compareTo(Photo o) {
		return getName().compareTo(o.getName());
	}

	public ImgLink getImgLink(String string) {
		return new ImgLink(getFirst("img", "size", string));
	}
}
